<?php

class ActivationController extends Controller
{
	public function actionIndex () {
		
		$email  = isset($_GET['email'])  ? $_GET['email']  : '';
		$secret = isset($_GET['secret']) ? $_GET['secret'] : '';
		
		$this->pageTitle = UserModule::t('Activation');

		Yii::app()->menu->set('breadcrumbs', array(
			UserModule::t('Users') => array('/user'),
			$this->pageTitle
		));
		
		if($email && $secret)
		{
			$model = User::model()->notsafe()->findByAttributes(array('email' => $email));
			
			if($model)
			{
				if($model->activate($secret))
				{
					if($model->status == User::STATUS_ACTIVE)
					{
					    $this->render(
							'index',
							array(
								'title'   => UserModule::t('Activation successful'),
								'content' => UserModule::t('Your account is now active.')
							)
						);
					}
					
					if($model->status == User::STATUS_PENDING)
					{
					    $this->render(
							'index',
							array(
								'title'   => UserModule::t('Activation successful'),
								'content' => UserModule::t('However, your account now pending review by an admin. We will inform you once the account has been activated.')
							)
						);
					}
				}
				else
				{
					if($model->status == User::STATUS_INACTIVE)
					{
					    $this->render(
							'index',
							array(
								'title'   => UserModule::t('Activation failure'),
								'content' => UserModule::t('Invalid activation request.')
							)
						);
					}

					if($model->status == User::STATUS_ACTIVE)
					{
					    $this->render(
							'index',
							array(
								'title'   => UserModule::t('Activation failure'),
								'content' => UserModule::t('Your account is already active.')
							)
						);
					}

					if($model->status == User::STATUS_PENDING)
					{
					    $this->render(
							'index',
							array(
								'title'   => UserModule::t('Activation failure'),
								'content' => UserModule::t('Your account is still pending. We will inform you once the account has been activated.')
							)
						);
					}

					if($model->status == User::STATUS_BANNED)
					{
					    $this->render(
							'index',
							array(
								'title'   => UserModule::t('Activation failure'),
								'content' => UserModule::t('Your account has been banned.')
							)
						);
					}
				}
			}
			else
			{
			    $this->render(
					'index',
					array(
						'title'   => UserModule::t('Activation failure'),
						'content' => UserModule::t('Invalid activation request.')
					)
				);
			}
		}
		else
		{
		    $this->render(
				'index',
				array(
					'title'   => UserModule::t('Activation failure'),
					'content' => UserModule::t('Invalid activation request.')
				)
			);
		}
	}

}